<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <a href="https://image1.suning.cn/uimg/b2c/newcatentries/0010128947-000000000614428161_1_800x800.jpg" download="模板文件.xlsx">下载</a>
    <button onclick="download()">下载（跨域）</button>

    <script>
        function download() {
            // var url = 'http://scdn.gongyi.qq.com/quiz/Exam-Template.xlsx';
            var url = 'https://image1.suning.cn/uimg/b2c/newcatentries/0010128947-000000000614428161_1_800x800.jpg'
            var xhr = new XMLHttpRequest();
            xhr.open('GET', url, true); // 异步
            xhr.responseType = 'blob'; // blob 类型
            xhr.onload = function () {
                if (xhr.status != 200) {
                    alert('下载异常！');
                    return;
                }
                if (window.navigator.msSaveOrOpenBlob) {
                    // IE
                    navigator.msSaveBlob(xhr.response, filename);
                } else {
                    var newUrl = window.URL.createObjectURL(xhr.response);
                    var a = document.createElement('a');
                    a.setAttribute('href', newUrl);
                    a.setAttribute('target', '_blank');
                    a.setAttribute('download', '模板文件.xlsx'); // 自定义文件名（有效）
                    document.body.appendChild(a);
                    a.click();
                    document.body.removeChild(a);
                }
            };
            xhr.send();
        }
    </script>
</body>

</html>